//
//  ViewController.m
//  动画
//
//  Created by MyMac on 15/8/1.
//  Copyright (c) 2015年 MyMac. All rights reserved.
//

#import "ViewController.h"
#import <POP.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UIButton *btm;
@property(nonatomic,strong)POPBasicAnimation*anBasc;
@property(nonatomic,strong)POPBasicAnimation*anColor;
@property(nonatomic,strong)POPSpringAnimation*anspring;
@property(nonatomic,strong)POPDecayAnimation*andecay;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //POPAnimatableProperty.h可用的动画属性,分视图属性或layer属性，但是貌似可以通用
    POPBasicAnimation*basci=[POPBasicAnimation animationWithPropertyNamed:kPOPLayerBounds];
   // basci.name=kPOPViewBounds;
    POPBasicAnimation*color=[POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
    self.anColor=color;
    color.toValue=@(0.4);
    color.duration=3.0;
    self.anBasc=basci;
    NSValue*value=[NSValue valueWithCGRect:CGRectMake(0, 0,100, 200)];
    basci.toValue=value;
    basci.beginTime=CACurrentMediaTime()+1.0;
    basci.duration=2.0;
    //控制动画的运行时间的中间过程速度
    basci.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [self.label addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew context:nil];
   
     [self.label addObserver:self forKeyPath:@"alpha" options:NSKeyValueObservingOptionNew context:nil];
    
    
 //弹性动画,,,没有duration，时间有下面几个属性控制
    POPSpringAnimation*spring=[POPSpringAnimation animationWithPropertyNamed:kPOPViewCenter];
    spring.toValue=[NSValue valueWithCGPoint:self.view.center];
    spring.springBounciness=10.0;//弹性的范围,控制振幅的
    spring.springSpeed=12.0;//速度，，动画速度
    spring.dynamicsFriction=1.0;//摩擦
    spring.dynamicsTension=3.0;//拉力
    spring.dynamicsMass=2.9;//质量
    self.anspring=spring;
    
 //衰减动画，同上，没有durtion
    POPDecayAnimation*decay=[POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionY];
   // decay.toValue=@(400);
    decay.velocity=@(600);
 //  decay.deceleration=1.0;//衰减系数，，越小，则衰减越快
    self.andecay=decay;
    
    
    
// POPAnimatableProperty*   prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {
//        // read value
//        prop.readBlock = ^(id obj, CGFloat values[]) {
//            values[0] = [obj volume];
//        };
//        // write value
//        prop.writeBlock = ^(id obj, const CGFloat values[]) {
//            [obj setVolume:values[0]];
//        };
//        // dynamics threshold
//        prop.threshold = 0.01;
//    }];
//    
    
    
    
}
//pop动画是不断在真实的改变视图的属性值的
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
   // if([keyPath isEqualToString:@"bounds"]){
//        NSValue*newValue=[change objectForKey];
        NSLog(@"%@",change);
    
    
    
   // }



}
- (IBAction)btnClick:(id)sender {
//    [self.label pop_addAnimation:self.anBasc forKey:@"basic"];
//    [self.label pop_addAnimation:self.anColor forKey:@"colaor"];
    //[self.label pop_addAnimation:self.anspring forKey:@"spring"];
    [self.label pop_addAnimation:self.andecay forKey:@"decay"];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
